#!/usr/bin/env ansible-playbook
---
- hosts: localhost
  vars:
    ansible_ask_become_pass: true

  tasks:
  - name: "Install Docker tools"
    community.general.pacman:
      name:
      - docker # Pack, ship and run any application as a lightweight container
      - docker-compose # Fast, isolated development environments using Docker
      - docker-buildx # Docker CLI plugin for extended build capabilities with BuildKit
      - buildkit # A toolkit for converting source code to build artifacts in a repeatable manner
      - podman # Tool and library for running OCI-based containers in pods
      - podman-compose # A script to run docker-compose.yml using podman
      - skopeo # A command line utility for various operations on container images and image repositories.
      - helm # The Kubernetes Package Manager
      - k9s # TUI for managing Kubernetes clusters and pods
      - kubectl # A command line tool for communicating with a Kubernetes API server
      - kubectx # Utility to manage and switch between kubectl contexts and Kubernetes namespaces
      state: latest
    become: yes

  - name: "Copy Docker Configuration file"
    ansible.builtin.copy:
      src: "{{ playbook_dir }}/config/docker/daemon.json"
      dest: /etc/docker/daemon.json
      mode: "0644"
    become: yes

  - name: "Enable nested virtualization"
    community.general.modprobe:
      name: kvm_intel
      params: "nested=1"
      state: present
    become: yes

  - name: "Install Libvirt and Virtualization tools"
    community.general.pacman:
      name:
      - libvirt # API for controlling virtualization engines (openvz,kvm,qemu,virtualbox,xen,etc)
      - qemu-base # A basic QEMU setup for headless environments
      - dmidecode # Desktop Management Interface table related utilities
      - dnsmasq # Lightweight, easy to configure DNS forwarder and DHCP server
      state: latest
    become: yes

  - name: "Install Additional tools for libvirt"
    community.general.pacman:
      name:
      - virt-install # Command line tool for creating new KVM , Xen, or Linux container guests using the libvirt hypervisor
      - virt-viewer # A lightweight interface for interacting with the graphical display of virtualized guest OS.
      - libguestfs # Access and modify virtual machine disk images
      state: latest
    become: yes

  - name: "Install DevOps tools"
    community.general.pacman:
      name:
      - minikube # A tool that makes it easy to run Kubernetes locally
      - vagrant # Build and distribute virtualized development environments
      state: latest
    become: yes

  - name: "Install Icedtea-web"
    community.general.pacman:
      name:
      - icedtea-web
      state: latest
    become: yes

  - name: "Set the UNIX domain socket group ownership to libvirt"
    ansible.builtin.lineinfile:
      path: /etc/libvirt/libvirtd.conf
      regexp: '^#unix_sock_group'
      line: 'unix_sock_group = "libvirt"'
      state: present
    become: yes

  - name: "Set the UNIX domain socket group ownership to libvirt"
    ansible.builtin.lineinfile:
      path: /etc/libvirt/libvirtd.conf
      regexp: '^#unix_sock_rw_perms'
      line: 'unix_sock_rw_perms = "0770"'
      state: present
    become: yes

  - name: "Install Cockpit"
    community.general.pacman:
      name:
      - cockpit # A systemd web based user interface for Linux servers
      - cockpit-machines # Cockpit UI for virtual machines
      - cockpit-podman # Cockpit UI for podman containers
      - cockpit-pcp # Cockpit support for reading PCP metrics and loading PCP archives
      state: latest
    become: yes

  - name: "Install Cockpit plugins from AUR"
    kewlfft.aur.aur:
      name: 
      - cockpit-zfs-manager # An interactive ZFS on Linux admin package for Cockpit
      - cockpit-file-sharing # A Cockpit plugin to easily manage samba and NFS file sharing.
      state: latest
    become: yes
    become_user: aur_builder

  - name: "Install kind for kubernetes"
    kewlfft.aur.aur:
      name: 
      - kind # Kubernetes IN Docker - local clusters for testing Kubernetes
      state: latest
    become: yes
    become_user: aur_builder

  - name: "Configure groups for current user"
    ansible.builtin.user:
      name: "{{ ansible_user_id }}"
      groups: "{{ item }}"
      append: yes
    become: yes
    loop:
    - docker
    - libvirt

  - name: "Enable Docker"
    ansible.builtin.systemd:
      name: "{{ item }}"
      state: started
      enabled: yes
    become: yes
    loop:
    - docker.socket
    - podman.socket
    - libvirtd.socket
    - cockpit.socket
...
